
<?php
// 分类添加
if(!empty($_POST)){

/*
  // 获取POST数据
  $name = $_POST['name'];
  $pid = $_POST['pid'];

  //插入语句
  $sql = "insert into `cate` (`name`,`pid`)values('$name','$pid')";

  //执行语句
  mysqli_query($link,$sql);
  //提取真值
  $_rows = mysqli_affected_rows($link);  //-1   0   1
*/
  $_rows = add('cate',$_POST);

  if($_rows>0){
     echo"<script>alert('提交成功');location.href='index.php?c=cate&a=list&admin=1';</script>";die;
  }else{
     echo"<script>alert('提交失败');history.go(-1)</script>";die;
  }

}

$id = empty($_GET['id'])?0:$_GET['id'];

//查询顶级分类
//
/*$sql = "select * from `cate` where pid=$id";

$result = mysqli_query($link,$sql);

while ($arr = mysqli_fetch_assoc($result)) {
  $cate[]=$arr;
}*/

$cate = getSelect('cate',"pid=$id");

//判断是否是ajax请求
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH'])){
  echo json_encode($cate);die;

}

//加载后台公共视图
 include (View_PATH.$admin.'/communal.html');


?>

